home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: Q: realloc->free?
- Date: Sun, 14 Jan 1996 16:53:48 GMT
- Organization: Netcom
- Message-ID: <30f93438.164984896@nntp.ix.netcom.com>
- References: <4daa2e$oh5@axe.netdoor.com>
- NNTP-Posting-Host: ix-dc18-06.ix.netcom.com
- X-NETCOM-Date: Sun Jan 14 8:53:09 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- esargent@netdoor.com (Eric Sargent) wrote:
-
- |> This is probably a dumb question, but I can't find any
- specific or
- |>exact information about this. Given this:
- |>
- |>char *a, *b;
- |>
- |>a = malloc(10);
- |>...
- |>/*
- |> later we need to increase the size
- |>*/
- |>...
- |>b = realloc(a, 100);
- |>
- |> Now let's say realloc had to move the data so a != b. Does
- realloc
- |>free the memory previously pointed to by a or should it be
- explicitly
- |>freed if realloc returns a new location? I checked the FAQ, but
- there
- |>was nothing specific about realloc. Thanks for any information.
-
- realloc() will free() the pointer if it has to allocate memory in a
- different location. You must not free the old pointer in this case
- and, in fact, according to the standard you cannot even meaningfully
- compare the returned pointer to the old one since the old one may
- refer to freed space.
-
-
- Michael M Rubenstein
-